package com.serial.comm.modular.serialPort.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.serial.comm.core.constants.SystemConstants;
import com.serial.comm.modular.serialPort.dao.OriginMapper;
import com.serial.comm.modular.serialPort.model.Origin;
import com.serial.comm.modular.serialPort.service.IOriginService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 原始电报信息表 服务实现类
 * </p>
 *
 * @author chentl123
 * @since 2020-02-21
 */
@Service
public class OriginServiceImpl extends ServiceImpl<OriginMapper, Origin> implements IOriginService {

    @Resource
    private OriginMapper originMapper;

    @Override
    public Integer createOriginTelegramAndGetId(Origin origin) {
        originMapper.createOriginTelegramAndGetId(origin);
        return origin.getId();
    }

    @Override
    public Origin getOriginBySourceId(Integer sourceId) {
        Wrapper<Origin> wrapper = new EntityWrapper<>();
        wrapper.eq(SystemConstants.Value.COLUMNS_SOURCE_ID, sourceId);
        Origin result = selectById(sourceId);

        return result;
    }

    @Override
    public Page<Origin> getWriteList(Page<Origin> page, Integer type, Integer success) {
        Wrapper<Origin> wrapper = new EntityWrapper<>();
        wrapper.eq(SystemConstants.Value.COLUMNS_TYPE, type)
                .eq(SystemConstants.Value.COLUMNS_SUCCESS, success)
                .orderBy(SystemConstants.Value.COLUMNS_ID, false);
        Page<Origin> list = selectPage(page, wrapper);
        return list;
    }
}
